﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Summerset.Isbndb.Authors
{
    /// <summary>
    /// An additional result field that provides information about a subject an author has a book about.    
    /// </summary>
    public sealed class AuthorElementSubject : ResponseElementChildBase
    {
        #region Constructor + Overridden Properties

        /* Element Example:
         <Subject subject_id="income_tax_reform" book_count="2">
          Income tax, Reform
         </Subject>
        */

        /// <summary>
        /// Initializes a new instance of the <see cref="AuthorElementSubject"/> class.
        /// </summary>
        /// <param name="element">The xml element that contains the underlying data for this instance.</param>
        public AuthorElementSubject(XmlElement element) 
            : base(element) { }

        /// <summary>
        /// Gets the expected name of the element.
        /// </summary>
        protected override string ExpectedElementName
        {
            get { return "Subject"; }
        }

        #endregion
        #region Properties

        /// <summary>
        /// Gets the isbndb.com subject id.  This value is unique to a subject.  
        /// SubjectId can be used to request further details from the subjects collection.
        /// </summary>
        public string SubjectId
        {
            get { return _element.Attributes["subject_id"].Value; }
        }

        /// <summary>
        /// Gets the number of books that are associated with this author in the ISBNDB.com api.
        /// </summary>
        public int BookCount
        {
            get { return int.Parse(_element.Attributes["book_count"].Value); }
        }

        /// <summary>
        /// Free-form text that identifies this author.
        /// </summary>
        public string Text
        {
            get { return _element.InnerText; }
        }

        #endregion
    }
}
